const {GithubUser} = require('../../models')

module.exports = [
  {
    /**
    * @api {get} /github/user [/github/user]
    * @apiGroup Github
    * @apiPermission none
    */
    url: '/github/user',
    method: 'get',
    request: async (req, res) => {
      try {
        const user = await GithubUser.findOne({
          where: {
            id: req.query.id
          }
        })
        req.session.user = user
        res.json(req.session.user)
      } catch (error) {
        res.status(400).json({error})
      }
    }
  }
]
